using UnityEngine;
using System.Collections;

/// \class  gkAbyssalGiantSubmarineSlowMotionController
/// \brief  The submarine slow motion controller
[AddComponentMenu("GK/AbyssalGiant/Submarine/gkAbyssalGiantSubmarineSlowMotionController")]
public class gkAbyssalGiantSubmarineSlowMotionController : MonoBehaviour 
{	
	/// The power consumption rate
	public float PowerConsumtionRate = 0.1f;
	
	/// The input
	private gkAbyssalGiantSubmarineInput m_rSubmarineInput;
	
	/// The power component
	private gkPowerComponent m_rPowerComponent;
	
	/// Default fixed time step
	private float m_fDefaultFixedTimeStep;
	
	/// \brief  Called just after the game begin to play
	void Start()
	{
		// Save the default fixed time step
		m_fDefaultFixedTimeStep = Time.fixedDeltaTime;
			
		// Grab the input
        m_rSubmarineInput = GetComponent<gkAbyssalGiantSubmarineInput>();
		
		// Get the power component
		m_rPowerComponent = GetComponent<gkPowerComponent>();
	}
	
	/// \brief  Event called each frame within the player controller
	void Update()
	{
		if(m_rSubmarineInput.IsSlowMotion() && (m_rPowerComponent.GetPower() > 0.0f))
		{
			Time.timeScale = 0.25f;
			Time.fixedDeltaTime = m_fDefaultFixedTimeStep * Time.timeScale;
			m_rPowerComponent.UsePower(PowerConsumtionRate * Time.deltaTime);
		}
		else
		{
			Time.timeScale = 1.0f;
			Time.fixedDeltaTime = m_fDefaultFixedTimeStep;
		}
	}
}
